package easyjava.hibernate.dao;

import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.query.Query;

import easyjava.hibernate.bean.StudentLogin;

public class StudentLoginDao {
	private Session session;
	public StudentLoginDao(Session session ){
		this.session=session;
	}
	
	public List<StudentLogin> list(){
		Query<StudentLogin> query =session.createQuery("from StudentLogin",StudentLogin.class);
		return query.getResultList();
	}
	public StudentLogin getStudentLoginById(int id){
		return session.get(StudentLogin.class, id);
	}
	
	public void insert(StudentLogin studentLogin) {
		Transaction tx = session.beginTransaction();
		try {

			session.save(studentLogin);
			tx.commit();
		} catch (HibernateException e) {
			e.printStackTrace();
			tx.rollback();
		}
	}
	public void update(StudentLogin studentLogin){
		Transaction tx = session.beginTransaction();
		try {

			session.update(studentLogin);
			tx.commit();
		} catch (HibernateException e) {
			e.printStackTrace();
			tx.rollback();
		}
		
	}
	public void delete(StudentLogin report){
		Transaction tx = session.beginTransaction();
		try {
			
			session.delete(report);
			tx.commit();
		} catch (HibernateException e) {
			e.printStackTrace();
			tx.rollback();
		}
		
	}

}
